import sys
from PySide import QtGui, QtCore

class Window(QtGui.QMainWindow):

    def __init__(self):
        super(Window, self).__init__()

        # Setting up the main window
        self.setGeometry(200, 200, 400, 300)
        self.setWindowTitle("Title of window")

        # Status bar
        # The status bar is a widget that is used for displaying status information
        self.statusBar().showMessage('Ready', 5000)

        # Progress bar
        # The progress bar widget can also be added to the status bar
        # Create the progress bar
        self.progressBar = QtGui.QProgressBar()
        # Add the progress bar as a permanent widget to the status bar
        self.statusBar().addPermanentWidget(self.progressBar)
        # This is simply to show the bar
        self.progressBar.setGeometry(30, 40, 200, 25)
        self.progressBar.setValue(50)

        # Menu bar
        # A menu consists of a list of action items.
        # The PySide.QtGui.QAction class provides an abstract user interface action that can be inserted into widgets.
        # A menu item with an icon
        exitAction = QtGui.QAction(QtGui.QIcon("exit.jpg"), "&Exit", self)
        exitAction.setShortcut("Ctrl+X")
        exitAction.setStatusTip("Exit the application!")
        # When we select this particular action, a triggered signal is emitted. The signal is connected to the close()
        # method of the QtGui.QMainWindow widget. This terminates the application.
        exitAction.triggered.connect(self.close)

        # A menu item without icon
        def testActionScr():
            print("TestAction")
        testAction = QtGui.QAction("test&Action", self)
        testAction.triggered.connect(testActionScr)

        # Here the actual menu is made and populated with action items
        menuBar = self.menuBar()
        fileMenu = menuBar.addMenu("&File")
        fileMenu.addAction(exitAction)  # Add the exit menu item
        fileMenu = menuBar.addMenu("&File2")
        fileMenu.addAction(testAction)  # Add the test menu item

        # Toolbars
        # Menus group all commands that we can use in an application.
        # Toolbars provide a quick access to the most frequently used commands.
        # Just like menus, toolbars can also use action items
        self.toolbar = self.addToolBar("Exit")
        self.toolbar.addAction(exitAction)
        self.toolbar.addAction(testAction)

if __name__ == "__main__":
    appObject = QtGui.QApplication(sys.argv)
    ex = Window()
    ex.show()
    sys.exit(appObject.exec_())

